﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Dts.Design;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Design;

namespace SSISJoost
{
    public partial class myFirstConnectionManagerEditor : Form
    {
        // Setting and getting ConnectionManager
        private ConnectionManager _connectionManager;
        public ConnectionManager ConnectionManager
        {
            get { return _connectionManager; }
            set { _connectionManager = value; }
        }

        // Setting and getting ServiceProvider
        private IServiceProvider _serviceProvider = null;
        public IServiceProvider ServiceProvider
        {
            get { return _serviceProvider; }
            set { _serviceProvider = value; }
        }

        // Default constructor
        public myFirstConnectionManagerEditor()
        {
            InitializeComponent();
        }

        // Interface connection
        public void Initialize(ConnectionManager connectionManager, IServiceProvider serviceProvider)
        {
            this._connectionManager = connectionManager;
            this._serviceProvider = serviceProvider;
        }

        // Page load: get url from properties
        private void myFirstConnectionManagerEditor_Load(object sender, EventArgs e)
        {
            this.txtDownloadUrl.Text = this._connectionManager.Properties["DownloadUrl"].GetValue(_connectionManager).ToString();
        }

        // Save: set url in properties
        private void btnOk_Click(object sender, EventArgs e)
        {
            this._connectionManager.Properties["DownloadUrl"].SetValue(this._connectionManager, this.txtDownloadUrl.Text);
            this.DialogResult = DialogResult.OK;
        }

        // Cancel dialog
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
